/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.transfer.service.impl;

import me.zhengjie.modules.transfer.domain.TransferIc91;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.zhengjie.modules.transfer.service.TransferIc91Service;
import me.zhengjie.modules.transfer.domain.dto.TransferIc91QueryCriteria;
import me.zhengjie.modules.transfer.mapper.TransferIc91Mapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import me.zhengjie.utils.PageUtil;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import me.zhengjie.utils.PageResult;

/**
* @description 服务实现
* @author lzw
* @date 2025-04-25
**/
@Service
@RequiredArgsConstructor
public class TransferIc91ServiceImpl extends ServiceImpl<TransferIc91Mapper, TransferIc91> implements TransferIc91Service {

    private final TransferIc91Mapper transferIc91Mapper;

    @Override
    public PageResult<TransferIc91> queryAll(TransferIc91QueryCriteria criteria, Page<Object> page){
        return PageUtil.toPage(transferIc91Mapper.findAll(criteria, page));
    }

    @Override
    public List<TransferIc91> queryAll(TransferIc91QueryCriteria criteria){
        return transferIc91Mapper.findAll(criteria);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(TransferIc91 resources) {
        transferIc91Mapper.insert(resources);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(TransferIc91 resources) {
        TransferIc91 transferIc91 = getById(resources.getAaz652());
        transferIc91.copy(resources);
        transferIc91Mapper.updateById(transferIc91);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<String> ids) {
        transferIc91Mapper.deleteBatchIds(ids);
    }

    @Override
    public void download(List<TransferIc91> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (TransferIc91 transferIc91 : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("系统跟踪流水号", transferIc91.getAaz341());
            map.put("转出地人员编号", transferIc91.getAac319());
            map.put("人员编号", transferIc91.getAac001());
            map.put("转出地行政区划代码", transferIc91.getAab301());
            map.put("参保地行政区划代码", transferIc91.getAab299());
            map.put("参保地名称", transferIc91.getAab300());
            map.put("年度", transferIc91.getAae001());
            map.put("缴费起始时间", transferIc91.getAae041());
            map.put("缴费终止时间", transferIc91.getAae042());
            map.put("月缴费基数", transferIc91.getAae180());
            map.put("缴费月数", transferIc91.getAae202());
            map.put("个人缴费比例", transferIc91.getAaa041());
            map.put("单位缴费划入个人账户比例", transferIc91.getAaa043());
            map.put("单位缴费比例", transferIc91.getAaa042());
            map.put("当年记账金额", transferIc91.getAae381());
            map.put("当年记账金额中的个人缴费部分", transferIc91.getAae264());
            map.put("当年记账利息", transferIc91.getAae269());
            map.put("当年记账利息中的个人缴费部分", transferIc91.getAae265());
            map.put("至本年末账户累计储存额", transferIc91.getAae382());
            map.put("至本年末账户累计储存额中的个人缴费部分", transferIc91.getAae273());
            map.put("基本养老保险关系转移接续信息表ID", transferIc91.getAaz756());
            map.put("人员参保关系ID", transferIc91.getAaz159());
            map.put("历年缴费流水号", transferIc91.getAaz751());
            map.put("备注", transferIc91.getAae013());
            map.put("经办人", transferIc91.getAae011());
            map.put("经办时间", transferIc91.getAae036());
            map.put("经办机构", transferIc91.getAab359());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
